﻿using PubSubGeneric.WCFContracts;
using PubSubGeneric.WCFPublishingServer;
using PubSubGeneric.WCFSubcriptionServer;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.ServiceModel;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WCFDemoHost
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            Trace.Listeners.Add(new ConsoleTraceListener());

            HostSubscriptionService();
            Console.WriteLine("Subscription Server is running ...");

            HostPublishingService();
            Console.WriteLine("Publishing Server is running ...");

            Console.ReadLine();
        }

        static ServiceHost _subscribeServiceHost;
        static ServiceHost _publishServiceHost;

        static void HostSubscriptionService()
        {
            try
            {
                _subscribeServiceHost = new ServiceHost(typeof(WCFSubscriptionServiceAdapter));
                _subscribeServiceHost.Open();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unhandled exception occurred in HostSubscriptionService, {0}", ex.Message);
            }
        }



        static void HostPublishingService()
        {
            try
            {
                _publishServiceHost = new ServiceHost(typeof(WCFPublishingServiceAdapter));
                _publishServiceHost.Open();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unhandled exception occurred in HostPublishingService, {0}", ex.Message);
            }
        }
    }
}
